using System;
using System.Collections.Generic;
using System.Text;
using Query;
using Index;
using Index.PostingLists;
using Index.PostingLists.Entry;
using Query.Queries;

namespace QueryTest
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
			WikiIndex index = new WikiIndex(@"E:\Wiki\index\", @"E:\Wiki\wikipedia-pl-html\pl");
            index.Open();


			FreeTextQuery query_engine = new FreeTextQuery(index);

			int[] docs = query_engine.SelectDocuments(new string[] { "aes" }, 10);

			foreach (int id in docs)
			{
				System.Diagnostics.Process.Start(index.GetURLToDocument(id));
				Console.WriteLine(index.GetURLToDocument(id));
			}

            testIntersect();
            */
            testSum();
        }

        public static void testSum()
        {
            DocumentPositionList[] tab = new DocumentPositionList[3];

            tab[0] = new DocumentPositionList();
            tab[1] = new DocumentPositionList();
            tab[2] = new DocumentPositionList();


            tab[0].Add(new PositionEntry(1, new int[] { 1 }));
            tab[0].Add(new PositionEntry(3, new int[] { 4 }));
            tab[0].Add(new PositionEntry(4, new int[] { 7, 11 }));
            tab[0].Add(new PositionEntry(8, new int[] { 10 }));
            tab[0].Add(new PositionEntry(11, new int[] { 13 }));

            tab[1].Add(new PositionEntry(2, new int[] { 2 }));
            tab[1].Add(new PositionEntry(4, new int[] { 9, 12 }));
            tab[1].Add(new PositionEntry(5, new int[] { 8 }));
            tab[1].Add(new PositionEntry(8, new int[] { 11 }));
            tab[1].Add(new PositionEntry(11, new int[] { 10, 14 }));

            tab[2].Add(new PositionEntry(4, new int[] { 13 }));
            tab[2].Add(new PositionEntry(8, new int[] { 12 }));

            List<int> result = Sum.sum(tab);
            foreach (int x in result)
            {
                Console.Write(x + " ");
            }

            Console.WriteLine("----------------------------");
            
            DocumentFrequencyList[] tab2 = new DocumentFrequencyList[3];

            tab2[0] = new DocumentFrequencyList();
            tab2[1] = new DocumentFrequencyList();
            tab2[2] = new DocumentFrequencyList();


            tab2[0].Add(new FrequencyEntry(1, 3));
            tab2[0].Add(new FrequencyEntry(2, 3));
            tab2[0].Add(new FrequencyEntry(5, 2));
            tab2[0].Add(new FrequencyEntry(8, 1));
            tab2[0].Add(new FrequencyEntry(90, 3));

            tab2[1].Add(new FrequencyEntry(2, 3));
            tab2[1].Add(new FrequencyEntry(90, 3));
            tab2[1].Add(new FrequencyEntry(111, 3));
            tab2[1].Add(new FrequencyEntry(123, 3));
            tab2[1].Add(new FrequencyEntry(1092, 3));

            tab2[2].Add(new FrequencyEntry(1, 30));
            tab2[2].Add(new FrequencyEntry(2, 32));


            List<int> result2 = Sum.sum(tab2);
            foreach (int x in result2)
            {
                Console.Write(x + " ");
            }
            
        }


        public static void testIntersect()
        {

            /*DocumentPositionList[] tab = new DocumentPositionList[3];

            tab[0] = new DocumentPositionList();
            tab[1] = new DocumentPositionList();
            tab[2] = new DocumentPositionList();


            tab[0].Add(new PositionEntry(1, new int[] { 1 }));
            tab[0].Add(new PositionEntry(3, new int[] { 4 }));
            tab[0].Add(new PositionEntry(4, new int[] { 7, 11 }));
            tab[0].Add(new PositionEntry(8, new int[] { 10 }));
            tab[0].Add(new PositionEntry(11, new int[]{ 13 }));

            tab[1].Add(new PositionEntry(2, new int[] { 2 }));
            tab[1].Add(new PositionEntry(4, new int[] { 9, 12 }));
            tab[1].Add(new PositionEntry(5, new int[] { 8 }));
            tab[1].Add(new PositionEntry(8, new int[] { 11 }));
            tab[1].Add(new PositionEntry(11,new int[] { 10, 14 }));

            tab[2].Add(new PositionEntry(4, new int[] { 13 }));
            tab[2].Add(new PositionEntry(8, new int[] { 12 }));


            DocumentPositionList[] result = Intersection.Intersect(tab);


            Query.Queries.PhraseQuery query = new Query.Queries.PhraseQuery(null);

           int[] a = query.DocumentWithPhrase(result);

           Console.WriteLine("-----");
           foreach (int x in a)
           {
               Console.WriteLine(x);
           }*/


        }
    }
}
